﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Control.Dal;

namespace Control.Bus
{
    public class BusImportBill
    {
        public int ID { get; set; }
        private BusStaff staff;
        public BusStaff Staff
        {
            set { staff = value; }
            get 
            {
                if (staff == null)
                    staff = new BusStaff();
                return staff;
            }
        }
        public DateTime Date { get; set; }


        public void Insert()
        {
            ID = DalImportBill.Insert(this);
        }

        public void DeleteAllDetail()
        {
            List<BusImportBillDetail> BillDetail = new List<BusImportBillDetail>();
            BillDetail = DalImportDetail.GetAllDetailByBill(this);
            foreach (BusImportBillDetail item in BillDetail)
            {
                item.Delete();    
            }
        }

     

        public static BusImportBill FindByDateAndStaff(DateTime dateTime, BusStaff staff)
        {
            BusImportBill resuilt = new BusImportBill()
            {
                ID = -1,
                Date = dateTime,
                Staff = staff,
            };

            List<BusImportBill> bills = new List<BusImportBill>();
            bills = DalImportBill.GetByStaff(staff);
            foreach (BusImportBill item in bills)
            {
                if (dateTime.ToShortDateString().CompareTo(item.Date.ToShortDateString()) == 0)
                {
                    resuilt = item;
                }
            }
            return resuilt;
        }

        public List<BusImportBillDetail> GetListBillDetails()
        {
            return DalImportDetail.GetAllDetailByBill(this);
        }
    }
}
